package com.markchu.admin.web;

import java.sql.*;
import org.apache.commons.dbutils.DbUtils;
import org.apache.commons.dbutils.QueryRunner;

public class DataWriter {
    public static void insertInto(String title,String area,String locations,String locations_tag,
                                  String tel,String thums,String open_time) throws SQLException {
        // 定义数据库连接信息
        String url = "jdbc:mysql://127.0.0.1:27860/timo";
        String username = "root";
        String password = "suggie8611";
        
        Connection conn = null;
        try {
            // 创建数据库连接

            conn = DriverManager.getConnection(url, username, password);
            
            // 创建 QueryRunner 对象
            QueryRunner queryRunner = new QueryRunner();
            // 将数据插入到数据库中
            int rowsAffected = queryRunner.update(conn, "INSERT INTO timo.web_hospital (title,area, locations,locations_tag,tel,thums,open_time) VALUES(?,?,?,?,?,?,?)",
                    title,area,locations,locations_tag,tel,thums,open_time);

            System.out.println("成功插入" + rowsAffected + "条记录。");

        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            // 关闭数据库连接
            DbUtils.closeQuietly(conn);
        }
    }
}